local cuifeng = fk.CreateSkill {
  name = "cuifeng",
  tags={Skill.Limited}
}

cuifeng:addEffect("viewas", {
  anim_type = "offensive",
  prompt = "#cuifeng-invoke",
  interaction = function(self, player)
    local names = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.is_damage_card and card.skill.target_num == 1 and not card.is_derived and
          player:canUse(card) and not player:prohibitUse(card) then
        table.insertIfNeed(names, card.name)
      end
    end
    return U.CardNameBox { choices = names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
})
cuifeng:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card)
    return card and table.contains(card.skillNames, "cuifeng")
  end,
})
cuifeng:addEffect(fk.TurnEnd, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:usedSkillTimes("cuifeng", Player.HistoryTurn) > 0 and player:hasSkill("cuifeng", true) then
      local n = 0
      player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        if use.from == player and table.contains(use.card.skillNames, "cuifeng") then
          if use.damageDealt then
            for _, p in ipairs(player.room:getAllPlayers()) do
              if use.damageDealt[p] then
                n = n + use.damageDealt[p]
              end
            end
          end
        end
        return false
      end, Player.HistoryTurn)
      return n ~= 1
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("cuifeng")
    player.room:notifySkillInvoked(player, "cuifeng", "special")
    player:setSkillUseHistory("cuifeng", 0, Player.HistoryGame)
  end,
})
return cuifeng
